# -*- coding: utf-8 -*-

import datetime
import pandas as pd
import time
import json
from pymongo import MongoClient
import sqlite3
"""
导入csv到mongodb
"""

# mongoDB IP地址
mongo_ip = "127.0.0.1"
# mongoDB 端口
mongo_port = 27017
# mongoDB 数据库名
mongo_db = "fx"
# mongoDB 集合名
mongo_collection = "event"
# csv文件地址
csv_path = "./data/event.csv"

conn= sqlite3.connect("./db/fxdata.db")


def get_timestamp(datestr):
    # print (datestr)
    d = datetime.datetime.strptime(datestr, '%Y-%m-%d %H:%M')
    return int(time.mktime(d.timetuple()))

df = pd.read_csv(csv_path,skiprows =1,names=["Time","country","eventName","beforeValue","nowValue","expectValue"])
print(df.head())
# 插入时间戳
df['timestamp'] = df.apply(lambda x:get_timestamp(x[0]),axis=1)
df.to_sql('event', conn, if_exists='append', index=False)
print('ok')




